package me.zhengjie.vo;

import com.google.common.collect.Maps;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import me.zhengjie.tool.NPETool;

import java.io.Serializable;
import java.util.Map;

/**
 * 复核级次
 */
@ApiModel("Step")
public class Step implements Serializable {

    private static final long serialVersionUID = 3768586518364166480L;
    @ApiModelProperty("总级次")
    private Integer total; //总级次
    @ApiModelProperty("当前级次")
    private Integer current; //当前级次

    public Step(Integer total) {
        NPETool.isEmptyThrowException(total, "复核总级次");
        this.total = total;
        this.current = 0;
    }


    public Step nextStep() {
        if (0 == this.total.intValue()) {
            return this;
        }
        Integer newCurrent = this.current + 1;
        if (newCurrent > this.total) {
            throw new IllegalArgumentException("复核总级次" + this.total + "当前级次" + newCurrent);
        }
        return new Step(this.total, newCurrent);
    }

    public Step previousStep() {
        if (0 == this.total.intValue()) {
            return this;
        }
        Integer newCurrent = this.current - 1;
        if (-1 > newCurrent) {
            throw new IllegalArgumentException("复核总级次" + this.total + "当前级次" + newCurrent);
        }
        return new Step(this.total, newCurrent);
    }

    public Step calNewStep(String aae016) {
        if ("0".equals(aae016)) {
            if (this.total.intValue() == this.getCurrent().intValue()) {
                return previousStep();
            }
            if (this.total.intValue() > this.getCurrent().intValue()) {
                throw new IllegalArgumentException("复核标志错误。 复核总级次:" + this.total + ",当前级次:" + this.current + ",复核标志:" + aae016);
            }
        }

        if ("3".equals(aae016) || "4".equals(aae016)) { //撤销或者回退
            return previousStep();
        } else {
            return nextStep();
        }
    }

    public Step lastStep() {
        return new Step(this.total, this.total);
    }

    private Step(Integer total, Integer current) {
        this.total = total;
        this.current = current;
    }



    public static Step rebuildStep(Integer total, Integer current) {
        return new Step(total, current);
    }

    public Map getAsMap() {
        Map map = Maps.newHashMap();
        map.put("bae416", this.total);
        map.put("aae419", this.current);
        return map;
    }

    public Integer getTotal() {
        return total;
    }

    public Integer getCurrent() {
        return current;
    }
}
